package com.squapsource.project_euler.utils;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Divisors {
	public static Set<Integer> getNumDivisors(int num) {
		Set<Integer> divisors = new HashSet<Integer>();
		divisors.add(1);

		for (int i = 2; i <= Math.sqrt(num); i++) {
			if (num % i == 0)
				divisors.add(i);
		}
		List<Integer> compositeDivisors = new ArrayList<Integer>();
		for (Integer divisor : divisors)
			compositeDivisors.add(num / divisor);

		divisors.addAll(compositeDivisors);
		return divisors;
	}

	public static boolean isAbundantNumber(int num) {
		Set<Integer> divisors = getNumDivisors(num);
		divisors.remove(num);
		int sum = 0;
		for (Integer divisor : divisors) {
			sum += divisor;

		}
		return sum > num;

	}
	
	public static Set<Integer> getAbundantNumbers() {
		Set<Integer> abundants = new HashSet<Integer>();
		for (int i=1; i<=28123; i++)
		{
			if (isAbundantNumber(i))
				abundants.add(i);
		}
		return abundants;
		
	}
}
